<?php

namespace app\utils\alarms;

use Guanguans\Notify\Factory;
use Throwable;

class DingTalkFactory implements AlarmsInterface
{
    /**
     * @param Throwable $throwable
     * @return void
     */
    public function push(Throwable $throwable): void
    {
        $request = request();
        Factory::dingTalk()
            ->setToken(config('alarms.dingTalk.token'))
            ->setSecret(config('alarms.dingTalk.secret'))
            ->setMessage((new \Guanguans\Notify\Messages\DingTalk\MarkdownMessage([
                'title' => $throwable->getMessage(),
                'text'  => "## " . date("H:i:s") . " 系统异常  \n ".
                    "> ### errorMessage： {$throwable->getMessage()} \n ".
                    "> ### path： {$request->path()} \n ".
                    "> ### file： {$throwable->getFile()} \n ".
                    "> ### line： {$throwable->getLine()} \n ",
            ])))
            ->send();
    }

    /**
     * @param array $info
     * @param string $title
     * @return void
     */
    public function pushInfo(bool $isSuccess, array $info,string $title): void
    {

    }
}
